import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String card = scanner.nextLine();
        int cur=0;
        //统计空格个数
        int count1=0;
        while(card.charAt(cur)!='-') {
            if(card.charAt(cur)==' ') {
                count1++;
            }
            cur++;
        }
        int count2=0;
        int mid=cur;
        cur++;
        while(cur<card.length()) {
            if(card.charAt(cur)==' ') {
                count2++;
            }
            cur++;
        }
        if(count1==0) {
            int len = card.length();
            String second = card.substring(mid+1,len);
            int dex1=0;
            while(card.charAt(dex1)!=' ') {
                dex1++;
            }
            String a=card.substring(0,dex1);
            if(a.equals("J")) {
                a="11";
            } else if()
            int dex2=mid;
            while(card.charAt(dex2)!=' ') {
                dex2++;
            }
            String b=card.substring(mid,dex2);

            //检查炸弹
            if(count2==1 && second.equals("joker JOKER")) {
                System.out.println("joker JOKER");
            } else if(count2==3) {
                System.out.println(second);
            } else if(count2==0) {             //如果同为个子 比较第一张牌大小
                if(Integer.parseInt(a)>Integer.parseInt(b)) {
                    System.out.println(card.substring(0,mid));
                } else {
                    System.out.println(second);
                }
            } else {
                System.out.println("ERROR");
            }
        } else if(count1==1) {
            int len = card.length();
            String second = card.substring(mid+1,len);
            int dex1=0;
            while(card.charAt(dex1)!=' ') {
                dex1++;
            }
            String a=card.substring(0,dex1);
            int dex2=mid;
            while(card.charAt(dex2)!=' ') {
                dex2++;
            }
            String b=card.substring(mid,dex2);
            if(card.substring(0,mid).equals("joker JOKER")) {
                System.out.println("joker JOKER");
                return;
            }
            if(count2==1) {
                if(second.equals("joker JOKER")) {
                    System.out.println("joker JOKER");
                } else {
                    if(Integer.parseInt(a)>Integer.parseInt(b)) {
                        System.out.println(card.substring(0,mid));
                    } else {
                        System.out.println(second);
                    }
                }
            } else if(count2==3) {
                System.out.println(second);
            } else {
                System.out.println("ERROR");
            }
        } else if(count1==2) {
            int len = card.length();
            String second = card.substring(mid+1,len);
            int dex1=0;
            while(card.charAt(dex1)!=' ') {
                dex1++;
            }
            String a=card.substring(0,dex1);
            int dex2=mid;
            while(card.charAt(dex2)!=' ') {
                dex2++;
            }
            String b=card.substring(mid,dex2);
            //检查炸弹
            if(count2==1 && second.equals("joker JOKER")) {
                System.out.println("joker JOKER");
            } else if(count2==3) {
                System.out.println(second);
            } else if(count2==2) {             //如果同为三子 比较第一张牌大小
                if(Integer.parseInt(a)>Integer.parseInt(b)) {
                    System.out.println(card.substring(0,mid));
                } else {
                    System.out.println(second);
                }
            } else {
                System.out.println("ERROR");
            }
        } else if(count1==3) {
            int len = card.length();
            String second = card.substring(mid+1,len);
            int dex1=0;
            while(card.charAt(dex1)!=' ') {
                dex1++;
            }
            String a=card.substring(0,dex1);
            int dex2=mid;
            while(card.charAt(dex2)!=' ') {
                dex2++;
            }
            String b=card.substring(mid,dex2);
            if(second.equals("joker JOKER")) {
                System.out.println("joker JOKER");
            } else if(count2==3) {
                if(Integer.parseInt(a)>Integer.parseInt(b)) {
                    System.out.println(card.substring(0,mid));
                } else {
                    System.out.println(second);
                }
            } else {
                System.out.println(card.substring(0,mid));
            }
        } else if(count1==4) {
            int len = card.length();
            String second = card.substring(mid+1,len);
            //第二手牌第一张牌
            int dex1=0;
            while(card.charAt(dex1)!=' ') {
                dex1++;
            }
            String a=card.substring(0,dex1);
            int dex2=mid;
            while(card.charAt(dex2)!=' ') {
                dex2++;
            }
            String b=card.substring(mid,dex2);
            if(second.equals("joker JOKER")) {
                System.out.println("joker JOKER");
            } else if(count2==3) {
                System.out.println(second);
            } else if(count2==4) {
                if(Integer.parseInt(a)>Integer.parseInt(b)) {
                    System.out.println(card.substring(0,mid));
                } else {
                    System.out.println(second);
                }
            } else {
                System.out.println("ERROR");
            }
        }
    }
}
